package com.atao.baokede.mapper;

import com.atao.baokede.pojo.AiDialogue;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * AI对话数据访问层
 */
@Mapper
public interface AiDialogueMapper {
    
    /**
     * 插入新的对话记录
     */
    @Insert("INSERT INTO ai_dialogue(user_id, user_message, ai_message, create_time) " +
            "VALUES(#{userId}, #{userMessage}, #{aiMessage}, NOW())")
    void insertDialogue(AiDialogue aiDialogue);
    
    /**
     * 根据用户ID获取最近N条对话记录
     */
    @Select("SELECT id, user_id, user_message, ai_message, create_time " +
            "FROM ai_dialogue " +
            "WHERE user_id = #{userId} " +
            "ORDER BY create_time DESC " +
            "LIMIT #{limit}")
    List<AiDialogue> getRecentDialogues(@Param("userId") Long userId, @Param("limit") int limit);
    
    /**
     * 清除指定用户的所有对话记录
     */
    @Select("DELETE FROM ai_dialogue WHERE user_id = #{userId}")
    void clearDialogues(@Param("userId") Long userId);
}
